package cn.ceplc.nlu.base.controller;


import cn.ceplc.nlu.base.domain.BaseEntity;
import cn.ceplc.nlu.base.service.BaseService;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

public class BaseController<T extends BaseEntity<PK>, PK extends Serializable> {

    protected BaseService<T, PK> baseService;

    @GetMapping("findAll")
    public List<T> findAll() {
        return baseService.findAll();
    }

    @GetMapping("findById")
    public Optional<T> findById(PK id) {
        return baseService.findById(id);
    }

    @PostMapping("insert")
    public T insert(@RequestBody T entity) {
        return baseService.insert(entity);
    }

    @PutMapping("update")
    public T update(@RequestBody T entity) {
        return baseService.update(entity);
    }

    @DeleteMapping("delete")
    public void delete(PK id) {
        baseService.delete(id);
    }
}
